<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Right</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="/resources/favicon.ico">
    <link rel="stylesheet" href="resources/layui/css/layui.css" th:href="@{/resources/layui/css/layui.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/resources/css/public.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/resources/layui_ext/dtree/dtree.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/resources/layui_ext/dtree/font/dtreefont.css}" media="all"/>
    <style>
        input#search_provideridTree_select_input_id {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        input#provideridTree_select_input_id {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        input#leaderprovideridTree_select_input_id {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        input.layui-input.layui-unselect {
            border-radius: 10px;
            height: 30px;
            margin-top: 4px;
        }
        .yxx-img{
            height: 200px;
        }
    </style>
</head>
<body>
<!--查询条件-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 15px;">
    <legend>搜索条件</legend>
</fieldset>
<form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">烧伤深度 </label>
            <div class="layui-input-inline">
                <select name="depth" id="depth">
                    <option value="-1">全部</option>
                    <option value="0">一度</option>
                    <option value="1">浅二度</option>
                    <option value="2">深二度</option>
                    <option value="3">三度</option>
                    <option value="4">数据未录入</option>
                </select>
            </div>
        </div>
        <div class="layui-inline" style="padding-left: 3%">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-radius" lay-submit="" lay-filter="doSearch"><i
                    class="layui-icon layui-icon-search layui-icon-normal"></i>查询
            </button>
            <button type="reset" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-warm"><i
                    class="layui-icon layui-icon-refresh"></i><span>重置</span>
            </button>
        </div>
    </div>
</form>

<!--数据表格-->
<div>
    <table class="layui-hide" id="woundTable" lay-filter="woundTable"></table>
    <div id="woundToolBar" style="display: none">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm layui-btn-normal layui-btn-radius" >
            <i class="layui-icon layui-icon-add-1"></i>添加创面标注信息
        </button>
    </div>
    <div id="woundRowBar" style="display: none;">
        <button type="button" lay-event="update" class="layui-btn layui-btn-sm layui-btn-radius"><i
                class="layui-icon layui-icon-edit"></i>编辑
        </button>
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger layui-btn-radius"><i
                class="layui-icon layui-icon-delete"></i>删除
        </button>
    </div>
</div>

<!--添加和修改弹出层-->
<div id="addDiv" style="display: none;padding: 10px;padding-right: 5%">
    <form action="" method="post" class="layui-form" id="addFrm" lay-filter="addFrm">
        <div class="layui-col-md9 layui-col-xs7">
            <div class="layui-form-item">
                <label class="layui-form-label">照片编号</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input input-radius" name="pictureId" lay-verify="required" placeholder="照片编号">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 7%">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit="" lay-filter="doSubmit"><i
                        class="layui-icon layui-icon-search layui-icon-normal"></i>提交
                </button>
                <button type="reset" class="layui-btn layui-btn-radius layui-btn-warm"><i
                        class="layui-icon layui-icon-refresh"></i><span>重置</span>
                </button>
            </div>
        </div>
    </form>
</div>
<div id="updateDiv" style="display: none;padding: 10px;padding-right: 5%">
    <form action="" method="post" class="layui-form" id="updateFrm" lay-filter="updateFrm">
        <div class="layui-col-md12 layui-col-xs12">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md9 layui-col-xs7">
                    <div class="layui-form-item magt3">
                        <!--隐藏的id-->
                        <input type="hidden" class="layui-input input-radius" name="id">
                        <label class="layui-form-label">烧伤深度</label>
                        <div class="layui-input-block">
                            <select name="depth"  disabled="disabled">
                                <option value="0">一度</option>
                                <option value="1">浅二度</option>
                                <option value="2">深二度</option>
                                <option value="3">三度</option>
                                <option value="4">数据未录入</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">照片编号</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input input-radius layui-disabled" name="pictureId" lay-verify="required" placeholder="照片编号">
                        </div>
                    </div>
                    <div class="layui-form-item pictureBox">
                        <label class="layui-form-label">照片</label>
                        <input type="hidden" name="picturePath" id="picturePath" value="/defaultImage.jpg">
                        <img class="yxx-img woundPicture" src="/file/loadCMImg?path=/defaultImage.jpg">
                    </div>
                    <div class="layui-form-item labelBox">
                        <label class="layui-form-label">标注</label>
                        <input type="hidden" name="labelPath" id="labelPath" value="/defaultImage.png">
                        <img class="yxx-img woundLabel" src="/file/loadCMLabel?path=/defaultImage.png">
                    </div>
                </div>
                <div class="layui-col-md3 layui-col-xs5">

                </div>
                <div class="layui-col-md3 layui-col-xs5">

                </div>


            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;padding-right: 7%">
                <button type="button" class="layui-btn layui-btn-radius" lay-submit="" lay-filter="doSubmit"><i
                        class="layui-icon layui-icon-search layui-icon-normal"></i>提交
                </button>
                <button type="reset" class="layui-btn layui-btn-radius layui-btn-warm"><i
                        class="layui-icon layui-icon-refresh"></i><span>重置</span>
                </button>
            </div>
        </div>
    </form>
</div>

<script type="text/javascript" src="/resources/layui/layui.js"></script>

<script type="text/javascript">

    layui.config({
        base: '/resources/layui_ext/',//静态资源所在路径
    }).extend({
        excel: 'excel',
    });


    //提升数据表格的作用域，因为底下还有一个reloadTable方法
    var tableIns;

    var queryData={'depth':'-1'};

    layui.use(['jquery', 'form', 'layer', 'table','upload','excel','laydate'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var table = layui.table;
        var upload = layui.upload;
        var depth_dic = {0:"一度", 1:"浅二度", 2:"深二度", 3:"三度",4:"数据未录入"};
        var excel=layui.excel;
        var laydate=layui.laydate;



        //初始化表格 加载数据
        tableIns = table.render({
            elem: "#woundTable",
            title: "创面标注信息表格",
            url: "/labeled-wound/loadAllInformation",
            toolbar: "#woundToolBar",
            page: true,
            height: "full-180",
            cols: [ [
                //{field: 'id', title: 'ID', align: 'center',width:'50'},
                {field: 'pictureId', title: '照片编号', align: 'center',width:'100'},
                {field: 'picturePath', title: '照片', align: 'center',width:'150',
                    templet:function (d) {
                        return '<img width=40 height=40 src=/file/loadCMImg?path='+d.picturePath+ ' />';
                    }},
                {field: 'labelPath', title: '标注', align: 'center',width:'150',
                    templet:function (d) {
                        return '<img width=40 height=40 src=/file/loadCMLabel?path='+d.labelPath+ ' />';
                    }},
                {field: 'depth', title: '烧伤深度', align: 'center',width:'100',
                    templet:function (d) {
                        return depth_dic[d.depth]
                    }},
                {field: 'changeTime', title: '上传时间', align: 'center',width:'100'},
                {fixed: 'right', title: '操作', toolbar: '#woundRowBar', align: 'center',width:'180'}
            ] ],
            done: function (data, curr, count) {
                //不是第一页时，如果当前返回的数据为0那么就返回上一页
                if (data.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: curr - 1
                        }
                    })
                }
            }
        });


        //监控模糊查询按钮事件
        form.on("submit(doSearch)", function (data) {
            queryData=data.field
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监控工具条事件
        table.on("toolbar(woundTable)", function (obj) {
            switch (obj.event) {
                case 'add':
                    openAddLayer();
                    break;
            };
        });

        //监控行工具条事件
        table.on("tool(woundTable)", function (obj) {
            //获取当前行数据
            var data = obj.data;
            switch (obj.event) {
                case 'delete':
                    deleteGoods(data);
                    break;
                case 'update':
                    updateGoods(data);
                    break;
            };
        });

        //图片上传
        upload.render({
            elem: '.labelBox',
            url: '/file/uploadCMLabel',
            acceptMime:'image/*',
            field:'mf',
            data: {
                oldPicturePath: function(){
                    return $("#labelPath").val();
                }
            },
            method : "post",
            done: function(res, index, upload){
                if(res.data.path)
                {
                    var path=res.data.path;
                    $('.woundLabel').attr('src','/file/loadCMLabel?path='+path);
                    $('.labelBox').css("background","#fff");
                    //给隐藏域赋值
                    $("#labelPath").val(path);
                }
            }
        });


        var mainIndex;
        var url;

        //打开添加弹出层
        function openAddLayer() {
            mainIndex = layer.open({
                type:1,
                content:$("#addDiv"),
                area:['500px','250px'],
                title:'添加创面标注信息',
                success:function () {
                    $("#addFrm")[0].reset();
                    url="/labeled-wound/addInformation";
                }
            });
        }


        //打开修改的弹出层
        function updateGoods(data) {
            mainIndex = layer.open({
                type:1,
                content:$("#updateDiv"),
                area:['750px','550px'],
                title:'修改创面标注信息',
                success:function () {
                    //清空原有的数据
                    $("#updateFrm")[0].reset();
                    //装载新的数据
                    form.val("updateFrm",data);
                    //图片进行回显
                    $(".woundPicture").attr("src","/file/loadCMImg?path="+data.picturePath);
                    //下拉列表的回显
                    url="/labeled-wound/updateInformation";
                }
            });
        }

        form.on("submit(doSubmit)",function (data) {
            console.log(data.field)
            $.post(url,data.field,function (res) {
                if (res.code==200){
                    tableIns.reload();
                }
                layer.msg(res.msg);
                layer.close(mainIndex);
            });
            return false;
        });

        //删除
        function deleteGoods(data) {
            layer.confirm('你确定要删除编号为【' + data.pictureId + '】的图片吗？', {icon: 3, title: '提示'}, function (index) {
                $.post("/labeled-wound/deleteInformation", {id: data.id,picturePath:data.picturePath},function (res) {
                    if(res.code==200){
                        tableIns.reload({
                            where:"",
                        });
                    }
                    layer.msg(res.msg);
                });
                layer.close(index);
            });
        }


    });


</script>

</body>
</html>